#ifndef _SOCKETIO_H
#define _SOCKETIO_H
#include <unistd.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string>

using std::string;

typedef struct train_s{
    int length; //该长度为json的长度
    int type;
    string jsonObj;
}train_t;

class SocketIO {
public: 
    SocketIO(int fd);
    int readn(char * buf, int len);
    int writen(char* buf, int len);
    int readLine(char* buf, int len);
    int readTrain(train_t& train);
    int writeTrain(const train_t& train);
    ~SocketIO();
private:
    int _fd;
};

#endif //_SOCKETIO_H
